<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Responsive Admin &amp; Dashboard Template based on Bootstrap 5">
    <meta name="author" content="AdminKit">
    <meta name="keywords"
          content="adminkit, bootstrap, bootstrap 5, admin, dashboard, template, responsive, css, sass, html, theme, front-end, ui kit, web">

    <link rel="shortcut icon" href="img/icons/icon-48x48.png"/>

    <title>宠物寄管系统</title>
    <style>
        .carousel-inner img {
            width: 100%;
            height: 100%;
        }
    </style>
    <link href="../cwjy/css/app.css" rel="stylesheet">
</head>

<script src="../cwjy/js/jquery.min.js" type="text/javascript"></script>
<body>
<div class="wrapper">
    <div class="main">
        <nav class="navbar navbar-expand navbar-light navbar-bg">
            <div style="width: 26%"></div>
            <div class="navbar-collapse collapse" id="navTopMenu">
                <ul class="navbar-nav ">
                    <!--           <li class="navbar-nav " >
                                   <a href="#"  style="color: orange;font-weight: bold;margin-right: 10px">请登录</a>
                               </li>-->
                    <li class="navbar-nav ">
                        <button class="btn btn-outline-secondary" onclick="shoppingHome()" href="#" style="font-weight: bold;margin-right: 10px" id="shoppingHome">
                            首页
                        </button>
                    </li>
                    <li class="navbar-nav ">
                        <a class="btn btn-outline-secondary" href="#" id="registration" style="font-weight: bold;margin-right: 10px">
                            免费注册
                        </a>
                    </li>
                    <li class="navbar-nav ">
                        <a class="btn btn-outline-secondary" id = "pet_boarding_add" href="#"  style="font-weight: bold;margin-right: 10px">
                            寄养宠物
                        </a>
                    </li>
                    <li class="navbar-nav ">
                        <a class="btn btn-outline-secondary" href="#" id="pet_boarding_table" style="font-weight: bold;margin-right: 10px">
                            寄养订单
                        </a>
                    </li>
                    <li class="navbar-nav ">
                        <a class="btn btn-outline-secondary" href="#" id="personal_order_inquiry" style="font-weight: bold;margin-right: 10px">
                            已购买物品
                        </a>
                    </li>
                    <li class="navbar-nav ">
                        <a class="btn btn-outline-secondary" href="#" id="product_reviews_order_user" style="font-weight: bold;margin-right: 10px">
                            订单评价
                        </a>
                    </li>
                    <li class="navbar-nav ">
                        <a class="btn btn-outline-secondary" href="#" id="product_reviews_boarding_user" style="font-weight: bold;margin-right: 10px">
                            寄养评价
                        </a>
                    </li>
                    <li class="navbar-nav ">
                        <a class="btn btn-outline-secondary" href="#" id="shipping" style="font-weight: bold;margin-right: 10px">
                            收货地址
                        </a>
                    </li>
                    <!--<li class="navbar-nav " style="margin-right: 10px">-->
                        <!--<div class="dropdown">-->
                            <!--<a type="button" class="btn btn-outline-secondary"-->
                                    <!--data-toggle="dropdown">寄养管理-->
                                <!--<span class="caret"></span>-->
                            <!--</a>-->
                            <!--<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">-->
                                <!--<li role="presentation">-->
                                    <!--<a role="menuitem" class="btn btn-outline-secondary" tabindex="-1" href="#"-->
                                       <!--style="font-weight: bold;margin-bottom: 10px;" id = "pet_boarding_add">宠物寄养</a>-->
                                <!--</li>-->
                                <!--<li role="presentation">-->
                                    <!--<a role="menuitem" class="btn btn-outline-secondary" tabindex="-1" href="#"-->
                                       <!--style="font-weight: bold;margin-right: 10px" id = "pet_boarding_table">寄养订单</a>-->
                                <!--</li>-->
                            <!--</ul>-->
                        <!--</div>-->
                    <!--</li>-->
                 <!--   <li class="navbar-nav ">
                        <div class="dropdown">
                            <button type="button" class="btn btn-outline-secondary" id="dropdownMenu1"
                                    data-toggle="dropdown">订单管理
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                                <li role="presentation">
                                    <a role="menuitem" class="btn btn-outline-secondary" tabindex="-1" href="#"
                                       style="font-weight: bold;margin-bottom: 10px" id ="personal_order_inquiry">已购买物品</a>
                                </li>
                                <li role="presentation">
                                    <a role="menuitem" class="btn btn-outline-secondary" tabindex="-1" href="#"
                                       style="font-weight: bold;margin-right: 10px" id="product_reviews_order">评价</a>
                                </li>
                            </ul>
                        </div>
                    </li>-->

                </ul>
                <ul class="navbar-nav navbar-align">
                    <li class="nav-item dropdown">
                        <a class="nav-icon dropdown-toggle" href="#" id="shoppingCart"  >
                            <div class="position-relative">
                                <i class="align-middle" data-feather="shopping-cart"></i>
                                <span class="indicator" id ='shoppingCartCount' style="display: none">0</span>
                            </div>
                        </a>
                    </li>
                    <div class="navbar-collapse collapse">
                        <ul class="navbar-nav navbar-align" id ="navUlTop">
                            <li class="nav-item dropdown">
                                <a class="nav-icon dropdown-toggle d-inline-block d-sm-none" href="#" >
                                    <i class="align-middle" data-feather="settings"></i>
                                </a>
                                <a class="nav-link dropdown-toggle d-none d-sm-inline-block" href="#" data-toggle="dropdown">
                                    <img src="../cwjy/img/avatars/avatar.jpg" class="avatar img-fluid rounded mr-1" id = "imagesTop"
                                         alt="Charles Hall"/> <span class="text-dark" id = "usernameTop">admin</span>
                                </a>
                                <div class="dropdown-menu dropdown-menu-right">
                                    <a class="dropdown-item" href="#" id = "grzx"><i class="align-middle mr-1"
                                                                                     data-feather="user"></i>
                                        个人中心</a>
                                    <div class="dropdown-divider"></div>
                                    <span class="dropdown-item" data-toggle="modal"
                                          data-target="#defaultModalPrimary1"><i class="align-middle mr-1"
                                                                                data-feather="settings"></i>
                               密码修改</span>
                                    <div class="dropdown-divider"></div>
                                    <a class="dropdown-item" href="#" id = "/cwjy/login_user">登出</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                </ul>
            </div>
            <div style="width: 25%"></div>
        </nav>

        <main class="content" id="mainS">
            <div class="row">
                <div class="col-12 col-md-2 col-lg-2"></div>
                <div class="col-12 col-md-8 col-lg-8" >
                    <div class="row" id = "shoppingDiv">
                        <div class="col-12 col-md-12 col-lg-12">
                            <div class="card">
                                <div id="demo" class="carousel slide" data-ride="carousel">
                                    <!-- 指示符 -->
                                    <ul class="carousel-indicators" >
                                        <li data-target="#demo" data-slide-to="0" class="active"></li>
                                        <li data-target="#demo" data-slide-to="1"></li>
                                        <li data-target="#demo" data-slide-to="2"></li>
                                    </ul>
                                    <!-- 轮播图片 -->
                                    <div class="carousel-inner">
                                        <div class="carousel-item active">
                                            <img src="https://static.runoob.com/images/mix/img_fjords_wide.jpg">
                                        </div>
                                        <div class="carousel-item">
                                            <img src="https://static.runoob.com/images/mix/img_nature_wide.jpg">
                                        </div>
                                        <div class="carousel-item">
                                            <img src="https://static.runoob.com/images/mix/img_mountains_wide.jpg">
                                        </div>
                                    </div>
                                    <!-- 左右切换按钮 -->
                                    <a class="carousel-control-prev" href="#demo" data-slide="prev">
                                        <span class="carousel-control-prev-icon"></span>
                                    </a>
                                    <a class="carousel-control-next" href="#demo" data-slide="next">
                                        <span class="carousel-control-next-icon"></span>
                                    </a>
                                </div>
                            </div>
                        </div>

                        <div id="shoppingDemo">
                            <div class="row" id="shoppingDemoRow">


                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12 col-xl-12 col-md-12 "><iframe src="webCWJY/pet_boarding_add.html" id="iframes" style="display: none"></iframe></div>
                </div>
            </div>
        </main>

        <footer class="footer">
            <div class="container-fluid">
                <div class="row text-muted">

                </div>
            </div>
        </footer>
    </div>
</div>

<!--模态框-->
<div class="modal fade" id="defaultModalPrimary" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="width: 150%;margin-left: -20%">
            <div class="modal-header" id="modelHead">
                <h3 class="modal-title" id="modelHeadText"
                    style="font-weight: bold;text-shadow: 1px 1px 3px #000000;">
                    狗粮A</h3>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body m-3" style="font-weight: bold;text-shadow: 0px 0px 0px #000000;font-size: 15px"
                 id="typeStyle">
                <div class="card-body" id="modelDiv" style="margin-top: -6%;font-weight: bold">

                </div>
            </div>
            <div class="modal-footer" id="modelAction">

            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="defaultModalPrimary1" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="margin-left: 3%;width: 120%">
            <div class="modal-header" id="modelHead1">
                <h3 class="modal-title" id="modelHeadText1" style="font-weight: bold;text-shadow: 1px 1px 3px #000000;">
                    密码修改</h3>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body m-3">
                <div class="card-body" id="modelDiv1" style="margin-top: -6%;font-weight: bold;">
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-2 text-sm-right">旧密码</label>
                        <div class="col-sm-10">
                            <input type="text" id="old_password" class="form-control" placeholder="旧密码" rows="3">
                        </div>
                    </div>
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-2 text-sm-right">新密码</label>
                        <div class="col-sm-10">
                            <input type="text" id="new_password" class="form-control" placeholder="新密码" rows="3">
                        </div>
                    </div>
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-2 text-sm-right">确认新密码</label>
                        <div class="col-sm-10">
                            <input type="text" id="qr_new_nassword" class="form-control" placeholder="确认新密码" rows="3">
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" id="modelAction1">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="passwordUpdate()">提交</button>
            </div>
        </div>
    </div>
</div>



<script src="../cwjy/js/app.js"></script>
<script type="text/javascript" src="../cwjy/js/ajaxAll.js"></script>
<script type="text/javascript">



    function passwordUpdate(){
        let old_password = $('#old_password').val()
        let new_password = $('#new_password').val()
        let qr_new_nassword =  $('#qr_new_nassword').val()
        if(new_password !== qr_new_nassword){
            alert('两次输入密码不正确，请重新输入！');
            return;
        }
        let url = "http://localhost:8888/cwjy/user/updatePassword";
        let json = {old_password:old_password, new_password:new_password, qr_new_nassword:qr_new_nassword};
        let success = "密码修改成功！";
        let error = "密码修改失败！";
        ajaxUnifiedCallUpdateAndAdd(url,json,success,error);
    }
    function initWidthHeight() {
        setTimeout(function () {
            $('#iframes').css("width", $('#mainS').width() * 0.67)
            $('#iframes').css("height", $('#mainS').height())
        },1000)
        $('#iframes').css("width", $('#mainS').width() * 0.67)
        $('#iframes').css("height", $('#mainS').height())
    }
    initWidthHeight();




  function shoppingHome(){
      getCommodityPage();
      $('#iframes').css("display","none");
      $('#shoppingDiv').css("display","block");
  }
    
    $('#navTopMenu a').click(function () {
        initWidthHeight();
        $('#iframes').attr("src", $(this)[0].id)
        $('#shoppingDiv').css("display","none");
        $('#iframes').css("display","block");
    })
    

    let commodityDataCache;

    function getCommodityPage() {
        let url = "http://localhost:8888/cwjy/Commodity/getPage";
        let json = {};
        $.ajax({
            type: 'post',
            async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: url,    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify(json),
            timeout: 10000,    //超时10s
            success: function (res) { returnLogin(res);
                commodityDataCache = res.data;
                forEachCommodity();
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('数据请求失败!');
            }
        });
    }

    getCommodityPage();

    function forEachCommodity() {
        let shoppingDemoRow = "";
        for (let i = 0; i < commodityDataCache.length; i++) {
            let temp = "     <div class=\"col-12 col-md-4 col-lg-3\">\n" +
                "                                    <a style=\"text-decoration: none\" data-toggle=\"modal\"\n" +
                "                                       data-target=\"#defaultModalPrimary\" onclick=\"SPXX('" + commodityDataCache[i].id + "')\">\n" +
                "                                        <div class=\"card\">\n" +
                "                                            <div class=\"card-header\" style=\"text-align: center\">\n" +
                "                                                <img  src=\"http://localhost:8888/cwjy/images/" + commodityDataCache[i].image_path + "\" style=\"width: 60%;height: 150px;\">\n" +
                "                                            </div>\n" +
                "                                            <div class=\"card-body\"\n" +
                "                                                 style=\"text-align: center;text-shadow: 1px 3px 5px #cccccc;font-weight: bold;font-size: 18px\">\n" +
                "                                                <p>" + commodityDataCache[i].product_name + "</p>\n" +
                "                                                <p>" + commodityDataCache[i].category_details_name + "</p>\n" +
                "                                                <p style=\"color: orange\">" + commodityDataCache[i].price + "</p>\n" +
                "                                            </div>\n" +
                "                                        </div>\n" +
                "                                    </a>\n" +
                "                                </div>";
            shoppingDemoRow += temp;
        }
        $('#shoppingDemoRow').html(shoppingDemoRow)
    }


    function removeNum() {
        let num = parseInt($('#num').val());
        if (num === 1) {
            alert("数量为 1 无法继续进行减少！")
            return;
        }
        $('#num').val(num - 1);
    }

    function addNum() {
        let num = parseInt($('#num').val())
        $('#num').val(num + 1);
    }

    $('#shoppingDemo .card').mousemove(function () {
        $(this).css("box-shadow", "0px 2px 2px 6px #ccc")
    })
    $('#shoppingDemo .card').mouseout(function () {
        $(this).css("box-shadow", "")
    })


    let CommodityData;

    function getByIdCommodityDate(id) {
        $.ajax({
            type: 'post',
            async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: 'http://localhost:8888/cwjy/Commodity/selectByPrimaryKey',    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify({id: id}),
            timeout: 10000,    //超时10s
            success: function (res) { returnLogin(res);
                /**生出成功刷新页面*/
                CommodityData = res.data;
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('数据请求失败!');
            }
        });
    }


    function getAddress() {
        $.ajax({
            type: 'post',
            async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: 'http://localhost:8888/cwjy/OrderShipping/getPage',    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify({}),
            timeout: 10000,    //超时10s
            success: function (res) { returnLogin(res);
                forEachAddress(res.data)
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('数据请求失败!');
            }
        });
    }


    function forEachAddress(data) {
        let address = "";
        for (let i = 0; i < data.length; i++) {
            let temp = "   <option value=\"" + data[i].id + "\">" +
                "姓名：" + data[i].receiver_name + "   手机号码：" + data[i].receiver_phone + "  收货地址：" + data[i].receiver_state
                + data[i].receiver_city + data[i].receiver_district + data[i].receiver_address + "" +
                "</option>"
            address += temp;
        }
        $('#order_shipping_id').html(address)
    }


    function SPXX(id) {
        getByIdCommodityDate(id);
        let data = CommodityData;
        let tempType = "";

        for (let i = 0; i < data.commodity_category_list.length; i++) {
            let tempTypeDivList = "";
            for (let j = 0; j < data.commodity_category_list[i].classification_detaileds.length; j++) {
                let tempTypeDiv = " <span> <button type=\"button\" name='" + data.commodity_category_list[i].type_name + "' class=\"btn btn-outline-secondary\"" +
                    " style=\"margin-bottom: 10px\">" + data.commodity_category_list[i].classification_detaileds[j].type_detailed + "" +
                    "</button></span>\n";
                tempTypeDivList += tempTypeDiv;
            }
            let tmps = "\n" +
                "                            <div style=\"width: 100%;\">\n" +
                "                                <div style=\"width: 20%;float: left\">\n" +
                "                                    " + data.commodity_category_list[i].type_name + "\n" +
                "                                </div>\n" +
                "                                <div style=\"width: 70%;float:left;text-align: left\">\n" +
                "" + tempTypeDivList + "" +
                "                                </div>\n" +
                "                            </div>\n" +
                "\n";
            tempType += tmps;
        }

        let temp = "      <div lass=\"mb-3\" style=\"width: 100%\">\n" +
            "                        <div style=\"width:50%;float: left\">\n" +
            "                            <img id ='imagesz' src=\"http://localhost:8888/cwjy/images/" + data.image_path + "\" style=\"width:100%;height: 500px\">\n" +
            "                        </div>\n" +
            "                        <div style=\"width:50%;float: left;text-align: center;margin-top: 2%\">\n" +
            "                            <p id='product_name' align='" + data.id + "'>" + data.product_name + "</p>\n" +
            "                            <div>\n" +
            "                                <p>\n" +
            "                                    <span>价格：￥</span>\n" +
            "                                    <span id='price'>" + data.price + "</span>\n" +
            "                                </p>\n" +
            "                                <p>\n" +
            "                                    <span>促销价：￥</span>\n" +
            "                                    <span style=\"color: red;\" id='sales_price'>" + data.sales_price + "</span>\n" +
            "                                </p>\n" +
            "                                <p>\n" +
            "                                    <span>运费：￥</span>\n" +
            "                                    <span style=\"color: red;\" id='post_fee'>" + data.post_fee + "</span>\n" +
            "                                </p>\n" +
            "                            </div>\n" +
            "                            <hr style=\"color: #ccc;width: 100%;margin-left: 6%\" size=\"4\"/>\n" +
            "                            <div style=\"width: 100%\">\n" +
            "                                <div style=\"width: 30%;border-right: 1px solid #ccc;float: left;margin-left: 10%\">\n" +
            "                                <span>\n" +
            "                                    <span>月销量</span>\n" +
            "                                    <span>" + data.sales_volume + "</span>\n" +
            "                                </span>\n" +
            "                                </div>\n" +
            "                                <div style=\"width: 30%;border-right: 1px solid #ccc;float: left\">\n" +
            "                                <span>\n" +
            "                                   <span>累计评价</span>\n" +
            "                                    <span>" + data.evaluation + "</span>\n" +
            "                                </span>\n" +
            "                                </div>\n" +
            "                                <span style=\"width: 30%\">\n" +
            "                                      <span>送积分</span>\n" +
            "                                    <span>" + data.integral + "</span>\n" +
            "                                </span>\n" +
            "                            </div>\n" +
            "                            <hr style=\"color: #ccc;width: 100%;margin-left: 6%\" size=\"4\"/>\n" +
            "<div id='pzxg'>" + tempType + "</div>" +
            "<div style=\"width: 100%;\">\n" +
            "                        <div style=\"width: 20%;float: left\">\n" +
            "                            留言\n" +
            "                        </div>\n" +
            "                        <div style=\"width: 70%;float:left;text-align: left\">\n" +
            "                            <textarea class=\"form-control\" style=\"resize: none;\" id='buyer_message'></textarea>\n" +
            "                        </div>\n" +
            "                    </div>" +
            "                            <div style=\"width: 100%;margin-bottom: 70%;margin-top: 60%\">\n" +
            "                                <div style=\"width: 20%;float: left\">\n" +
            "                                    数量\n" +
            "                                </div>\n" +
            "                                <div style=\"width: 70%;float:left;text-align: left;height: 30px\">\n" +
            "                                    <button type=\"button\"  data-feather=\"minus\" onclick=\"removeNum()\"></button>\n" +
            "                                    <input type=\"text\"  style=\"width: 40px;text-align: center\" value=\"1\" id = \"num\">\n" +
            "                                    <button type=\"button\" data-feather=\"plus\" onclick=\"addNum()\" ></button>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "  <div style=\"width: 100%;\">\n" +
            "                        <div style=\"width: 20%;float: left\">\n" +
            "                            收货地址\n" +
            "                        </div>\n" +
            "                        <div style=\"width: 70%;float:left;text-align: left\">\n" +
            "                           <select class=\"form-control\" id='order_shipping_id'></select>\n" +
            "                        </div>\n" +
            "                    </div> \n" +
            "\n" +
            "                            <div style=\"text-align: center;margin-top: 80%\">\n" +
            "                                <div style=\"width: 50%;float: left\">\n" +
            "                                    <button type=\"button\" class=\"btn btn-danger\" onclick='test()'>立即购买</button>\n" +
            "                                </div>\n" +
            "                                <div style=\"width: 50%;float:left;\">\n" +
            "                                    <button type=\"button\" class=\"btn btn-warning\" onclick='addCart()'>加入购物车</button>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                        </div>\n" +
            "                    </div>";
        $('#modelDiv').html(temp)
        feather.replace();

        $("#pzxg button").click(function () {
            $(this).parent().parent().find("button").each(function () {
                $(this).css("background-color", "");
                $(this).css("color", "#6C757D");
            })
            $(this).css("background-color", "#6C757D");
            $(this).css("color", "#FFFFFF");
        })


        getAddress();
    }

    function test() {
        let imagesArray =  $('#imagesz').attr("src").split("/");
        let index = 0;
        let commodity_type = "";
        $("#pzxg button").each(function () {
            if ("rgb(108, 117, 125)" === $(this).css("background-color")) {
                commodity_type += $(this)[0].name + "：" + $(this).html() + "  ";
                index++;
            }
        })
        if (index !== CommodityData.commodity_category_list.length) {
            alert("有类型选项未选择，请选择！")
            return;
        }
        let payment = $('#sales_price').html();
        let post_fee = $('#post_fee').html();
        let commodity_id = $('#product_name')[0].align;
        let buyer_message = $('#buyer_message').val();
        let num = $('#num').val();
        let order_shipping_id = $('#order_shipping_id').val();
        let totle_fee = (payment * num);
     /*   let json = {
            "payment": payment, "post_fee": post_fee, "commodity_id": commodity_id,
            "buyer_message": buyer_message, "commodity_type": commodity_type, "order_shipping_id": order_shipping_id
            , "commodity_num": num,"pic_path": imagesArray[imagesArray.length - 1 ]
        }*/
        let addOrderArray = [];
        let jsonItem = {
            "price": payment, "item_id": commodity_id,
            "pic_type": commodity_type, "num": num,
            "pic_path": imagesArray[imagesArray.length - 1 ],
            "totle_fee": totle_fee
        }
        addOrderArray[addOrderArray.length] = jsonItem;
        let json = {
            payment: totle_fee,
            post_fee: post_fee,
            order_item: addOrderArray,
            order_shipping_id: order_shipping_id,
            buyer_message: buyer_message
        }
        addOrder(json)
    }


    function addCart() {
        let index = 0;
        let commodity_type = "";
        $("#pzxg button").each(function () {
            if ("rgb(108, 117, 125)" === $(this).css("background-color")) {
                commodity_type += $(this)[0].name + "：" + $(this).html() + "  ";
                index++;
            }
        })
        if (index !== CommodityData.commodity_category_list.length) {
            alert("有类型选项未选择，请选择！")
            return;
        }
        let payment = $('#sales_price').html();
        let post_fee = $('#post_fee').html();
        let commodity_id = $('#product_name')[0].align;
        let buyer_message = $('#buyer_message').val();
        let num = $('#num').val();
        let order_shipping_id = $('#order_shipping_id').val();
        let json = {
            "payment": payment, "post_fee": post_fee, "commodity_id": commodity_id,
            "buyer_message": buyer_message, "commodity_type": commodity_type, "order_shipping_id": order_shipping_id
            , "commodity_num": num
        }
        let url = "http://localhost:8888/cwjy/ShoppingCart/insert";
        let success = "加入成功！";
        let error = "加入失败！";
        ajaxUnifiedCallUpdateAndAdd(url,json,success,error);
    }
    function addOrder(json) {
        $.ajax({
            type: 'post',
            async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: 'http://localhost:8888/cwjy/Order/insert',    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify(json),
            timeout: 10000,    //超时10s
            success: function (res) {
                returnLogin(res);
                /**生出成功刷新页面*/
                if (parseInt(res.data) > 0) {
                    alert("增加成功")
                    window.location.reload();
                } else {
                    alert("增加失败")
                }
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('数据请求失败!');
            }
        });
    }

   function getCatCount(){
        let json = {};
        let url = "";
       $.ajax({
           type: 'post',
           async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
           url: 'http://localhost:8888/cwjy/ShoppingCart/getCount',    //请求发送到Servlet
           contentType: 'application/json;charset=UTF-8',//指定消息请求类型
           data: JSON.stringify(json),
           timeout: 10000,    //超时10s
           success: function (res) {
               returnLogin(res);
               if(parseInt(res.data) > 0){
                   $('#shoppingCartCount').html(res.data)
                   $('#shoppingCartCount').css("display","block")
               }
           },
           error: function (errorMsg) {
               //请求失败时执行该函数
               alert('数据请求失败!');
           }
       });
   }

    getCatCount();


    let grzxDataCache;


    function getGrzxData() {
        $.ajax({
            type: 'post',
            async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: 'http://localhost:8888/cwjy/user/getUsername',    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify({}),
            timeout: 10000,    //超时10s
            success: function (res) { returnLogin(res);
                grzxDataCache = res.data;
                forEachgrzxDataCache()
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('数据请求失败!');
            }
        });
    }

    function forEachgrzxDataCache() {
        $('#usernameTop').html(grzxDataCache.username);
        $('#imagesTop').attr("src","http://localhost:8888/cwjy/images/"+grzxDataCache.images_path)
        if(grzxDataCache.username !== null){
            $('#registration').css("display","none");
        }
    }

    getGrzxData();
</script>

</body>

</html>